<?php

/**
 * actions.php
 * 
 * @(#) $Id: cookie_oauth_client.php,v 1.2 2013/08/14 12:44:50 mlemos Exp $
 * 
 */

if (!defined('ipos')) die("Please contact Y!m: ichphien_pro or Email: ichphien_pro@yahoo.com.");

if(in_array($value[0], array('the-loai','quoc-gia','danh-sach','tag','tim-kiem'))) {
	$ipid		=	$value[1];
	// get category id
	$categoryid		= 	explode("&categoryid=",URL_LOAD);
	$categoryid		=	intval($categoryid[1]);
	// get country id
	$countryid		= 	explode("&countryid=",URL_LOAD);
	$countryid		=	intval($countryid[1]);
	// order
	$order			= 	explode("order=",URL_LOAD);
	$order			=	explode("&",$order[1]);
	$order			=	$order[0];
	// page
	$page		= 	explode("?p=",URL_LOAD);
	$page		=	intval($page[1]);
	if($page == 0) {
		$page		= 	explode("&p=",URL_LOAD);
		$page		=	intval($page[1]);
	}
	$num		= 	FILM_PAGE;
	$num 		= 	intval($num);
	$page 		= 	intval($page);
	if (!$page) 	$page = 1;
	$limit 		= 	($page-1)*$num;
	if($limit<0) 	$limit=0;
	//begin code
	if($value[0] == "the-loai") {
		$categoryA	=	$db->database("danhmucid,danhmucten","category","danhmucten_kd = '$ipid'");
		$sql_where	=	"ipos_film.theloai LIKE '%,".$categoryA[0][0].",%'";
		$h2title	=	"Phim ".$categoryA[0][1];
		$urlpages	=	'the-loai/'.$ipid.'.html';
		$webtitle	=	"Phim ".$categoryA[0][1].' - Xem Phim '.$categoryA[0][1].' 2012 má»›i nháº¥t';
		$webdesc	=	"Phim ".$categoryA[0][1].", Xem phim ".$categoryA[0][1]." 2012 má»›i nháº¥t, phim ".$categoryA[0][1]." hot 2012";
		$webkey		=	"Phim ".$categoryA[0][1]." 2012, xem phim ".$categoryA[0][1]." 2012, ".$categoryA[0][1]." movie";
		$head		=	"<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"".MAIN_URL."/rss?c=$ipid\" />\n";
		$showDl1	=	1;
		
	}
	elseif($value[0] == "quoc-gia") {
		$countryA	=	$db->database("quocgiaid,quocgiaten","country","quocgiaten_kd = '$ipid'");
		$sql_where	=	"ipos_film.quocgia = '".$countryA[0][0]."'";
		$h2title	=	"Phim ".$countryA[0][1];
		$urlpages	=	'quoc-gia/'.$ipid.'.html';
		$webtitle	=	"Phim ".$countryA[0][1]." - Xem Phim ".$countryA[0][1]." 2012 má»›i nháº¥t";
		$webdesc	=	"Phim ".$countryA[0][1].", Xem phim ".$countryA[0][1]." 2012 má»›i nháº¥t, phim ".$countryA[0][1]." hot 2012";
		$webkey		=	"Phim ".$countryA[0][1]." 2012, xem phim ".$countryA[0][1]." 2012, ".$countryA[0][1]." movie";
		$showDl3	=	1;
	}
	elseif($value[0] == "tag" || $value[0] == "tim-kiem") {
		$tags		=	$value[1];
		$tagP		=	str_replace(" ","+",$tags);
		if($value[0] == "tag") {
			$sql_where	=	"ipos_film_info.phimtag LIKE '%$tags%'";
			$h2title	=	"$tags";
			$urlpages	=	'tag/'.$tagP.'.html';
			$webtitle	=	"Tuyá»ƒn táº­p phim $tags | Phim $tags";
			$webdesc	=	"tuyá»ƒn táº­p $tags, xem phim $tags online, mediafire $tags, download $tags";
			$webkey		=	"tuyá»ƒn táº­p $tags, $tags, $tags online, tai $tags, download $tags";
		}elseif($value[0] == "tim-kiem") {
			$sql_where	=	"ipos_film_info.timkiem like '%$tags%'";
			$h2title	=	"$tags";
			$urlpages	=	'tim-kiem/'.$tagP.'.html';
			$webtitle	=	"$tags, Xem phim $tags";
			$webdesc	=	"Phim $tags, xem phim $tags, chi tiáº¿t vá»� $tags";
			$webkey		=	"$tags, xem $tags, $tags online, tai $tags, download $tags";
		}
	}
	elseif($value[0] == "danh-sach") {
		$year		= 	explode("?year=",URL_LOAD);
		$year		=	intval($year[1]);
		$urlpages	=	'danh-sach/'.$ipid.'.html';
		if($value[1] == "phim-le") {
			$sql_where	=	"ipos_film.phimbo = 0";
			$ntitle		=	"Phim Láº»";
		}
		elseif($value[1] == "phim-bo") {
			$sql_where	=	"ipos_film.phimbo IN (1,2)";
			$ntitle		=	"Phim Bá»™";
		}
		elseif($value[1] == "phim-chieu-rap") {
			$sql_where	=	"ipos_film.phimchieurap = 1";
			$ntitle		=	"Phim Chiáº¿u Ráº¡p";
		}
		elseif($value[1] == "phim-moi") {
			$sql_where	=	"ipos_film.phimid != 0";
			$ntitle		=	"Phim Má»›i";
		}
		$h2title	=	"$ntitle";
		$webtitle	=	"$ntitle, Danh sÃ¡ch $ntitle chá»�n lá»�c";
		$webdesc	=	DECWEB;
		$webkey		=	"$ntitle,download $ntitle";
		
		// year
		if($year > 0) {
			$sql_where	.=	" AND ipos_film.namsanxuat = '$year'";
			$h2title	.=	" $year";
			$urlpages	.=	"?year=$year";
			$webtitle	=	"$ntitle $year, Danh sÃ¡ch $ntitle $year chá»�n lá»�c";
			$webdesc	=	DECWEB;
			$webkey		=	"$ntitle $year,download $ntitle $year";
		}
	}
	
	// order
	if($order) {
		if($order == 'new')			$sql_order	=	"ORDER BY ipos_film.phimid DESC";
		elseif($order == 'view')	$sql_order	=	"ORDER BY ipos_film.viewed DESC";
		elseif($order == 'year')	$sql_order	=	"ORDER BY ipos_film.namsanxuat DESC";
		elseif($order == 'name')	$sql_order	=	"ORDER BY ipos_film.tenphim ASC";
		if($year) $urlpages	.=	"$order=$order";
		else	$urlpages	.=	"?order=$order";
	}
	// category
	if($categoryid) {
		$sql_where	.=	" AND ipos_film.theloai LIKE '%,$categoryid,%'";
		$urlpages	.=	"&categoryid=$categoryid";
	}
	// country
	if($countryid) {
		$sql_where	.=	" AND ipos_film.quocgia = '$countryid'";
		$urlpages	.=	"&countryid=$countryid";
	}
	$pc1		= 	explode("?",URL_LOAD);
	if(count($pc1)>1)	$urlpages	.=	"&p=";
	else	$urlpages	.=	"?p=";
	$urlpages			=	str_replace(".html&p=",".html?p=",$urlpages);
	//end list
	if(!$sql_where) 	$sql_where	=	"ipos_film.phimid > 0";
	if(!$sql_order) 	$sql_order	=	"ORDER BY ipos_film.phimtime DESC";
	$phim		=	$db->database("ipos_film.phimid,
									ipos_film.tenphim,
									ipos_film.tentienganh,
									ipos_film.phimimg,
									ipos_film.thoiluong,
									ipos_film.chatluong",
									"film  JOIN ipos_film_info ON (ipos_film_info.phimid = ipos_film.phimid)","$sql_where $sql_order LIMIT $limit,$num");
	if($phim) {
		$total		=	$db->database("ipos_film.phimid","film JOIN ipos_film_info ON (ipos_film_info.phimid = ipos_film.phimid)",
										"$sql_where ORDER BY ipos_film.phimid DESC");
		$total		=	count($total);
		$pagehtml 	= 	ipos_pages($total,$num,$page,$urlpages);
	}
}
elseif($value[0] == "phim") {
	$ipid		= 	explode("_",URL_LOAD);
	$ipid		=	$ipid[1];
	if ($ipid) {
		$ipid = $ipid;
		$ipid = decode_id($ipid);
	}
	else {
		$ipid		= 	explode(".",URL_LOAD);
		$ipid		=	$ipid[1];
	}
	// láº¥y dá»¯ liá»‡u phim
	$info	=	$db->database("ipos_film.tenphim,
								ipos_film.tentienganh,
								ipos_film.daodien,
								ipos_film.dienvien,
								ipos_film.theloai,
								ipos_film.thoiluong,
								ipos_film.nhasanxuat,
								ipos_film.namsanxuat,
								ipos_film.phimimg,
								ipos_film.chatluong,
								ipos_film.viewed,
								ipos_film.trailer,
								ipos_film.server,
								ipos_film_info.phimtxt,
								ipos_film_info.phiminfo,
								ipos_film_info.phimtag,
								ipos_film_info.timkiem,
								ipos_film.quocgia,
								ipos_film.viewed_day,
								ipos_film.phimbo",
								"film JOIN ipos_film_info ON (ipos_film_info.phimid = ipos_film.phimid)","ipos_film.phimid = '$ipid'");

	if($info[0][2]=="") {
			$info[0][2]	=	get_ascii($info[0][1]);
	}
	$tenphim		=	check_name($info[0][0]);
	$tentienganh	=	check_name($info[0][1]);
	$daodien		=	check_name(get_tags('tim-kiem',$info[0][2]));
	$dienvien		=	check_name(get_tags('tim-kiem',$info[0][3]));
	$theloai		=	get_category($info[0][4],1);
	$thoiluong		=	check_name($info[0][5]);
	$nhasanxuat		=	check_name(get_tags('tim-kiem',$info[0][6]));
	$namsanxuat		=	check_name($info[0][7]);
	$phimimg		=	check_name($info[0][8]);
	$chatluong		=	check_name($info[0][9]);
	$luotxem		=	number_format($info[0][10]);
	$trailer		=	$info[0][11];
	$server			=	$info[0][12];
	$quocgia			=	get_country($info[0][17]);
	$phimtxt		=	$info[0][13];
	$phiminfo		=	$info[0][14];
	$tags			=	get_tags('tag',$info[0][15],1);
	if ($info[0][19] == 1) $loaiphim = 'PMIM Bá»˜';
	if ($info[0][19] == 0) $loaiphim = 'PMIM Láºº';
	if ($info[0][19] == 2) $loaiphim = 'PMIM Bá»˜';
	//xem phim
	if($server > 0)		$where_ep	=	" AND server = '$server'";
	$play	 		=	$db->database("epid","ep","phimid = '$ipid' $where_ep ORDER BY epid ASC LIMIT 1");
	$playurl		=	url_link($tenphim."-".$tentienganh,$play[0][0],"xem-phim");
	
	$webtitle	=	"Xem Phim $tenphim - $tentienganh $chatluong";
	if($info[0][15])
		$webkey		=	$info[0][15].",".$info[0][16];
	else
		$webkey		=	$info[0][16];
	$webdesc	=	"$phimtxt";
	
	//add
	$phimimgz	=	MAIN_URL."/".film_img($phimimg,1);
	$head		=	"<meta property=\"og:url\" content=\"".MAIN_URL.URL_LOAD."\" />
	<meta property=\"og:title\" content=\"$webtitle\">
	<meta property=\"og:description\" content=\"$webdesc\" />
	<meta property=\"og:image\" content=\"$phimimgz\" />\n";
	
	autotag($ipid);
}
elseif($value[0] == "xem-phim") {
	$ipid		= 	explode("_",URL_LOAD);
	$ipid		=	$ipid[1];
	if ($ipid) {
		$ipid		=	$ipid;
		$ipid = decode_id($ipid);
	}
	else {
		$ipid		= 	explode(".",URL_LOAD);
		$ipid		=	$ipid[1];
	}
	//id phim
	$play	 	=	$db->database("phimid,server","ep","epid = '$ipid'");
	if(!$play)		header("Location: ".ERROR);
	$phimid		=	$play[0][0];
	// up lÆ°á»£t xem
	$db->dbupdate("film","viewed=viewed+1, viewed_day=viewed_day+1","phimid='$phimid'");
	// thÃ´ng tin phim
	$info	=	$db->database("ipos_film.tenphim,
								ipos_film.tentienganh,
								ipos_film.theloai,
								ipos_film.namsanxuat,
								ipos_film.phimimg,
								ipos_film.chatluong,
								ipos_film.viewed,
								ipos_film_info.phimtxt,
								ipos_film_info.phimtag,
								ipos_film_info.timkiem",
								"film JOIN ipos_film_info ON (ipos_film_info.phimid = ipos_film.phimid)","ipos_film.phimid = '$phimid'");	
	$user	 	=	$db->database("usergroup,
								  username,
								  password,
								  email,
								  usercode,
								  sex,
								  fullname,
								  regdate,
								  birthday,
								  avatar","user","userid = '".$_SESSION["ipos_userid"]."'");
	$avatar			=	$user[0][9];
	$tenphim		=	check_name($info[0][0]);
	$tentienganh	=	check_name($info[0][1]);
	$theloai		=	get_category($info[0][2],1);
	$namsanxuat		=	check_name($info[0][3]);
	$phimimg		=	check_name($info[0][4]);
	$chatluong		=	check_name($info[0][5]);
	$luotxem		=	number_format($info[0][6]);
	$phimtxt		=	check_name($info[0][7]);
	$tags			=	get_tags('tag',$info[0][8],1);
	$server			=	$play[0][1];
	$phimurl		=	url_link($tenphim."-".$tentienganh,$phimid,"phim");
	$fpla 			=   MAIN_URL . "/js/flowplayer-3.2.13.js"; 
	$java			=	'<script src="' . $fpla . '" type="text/javascript" charset="utf-8"></script>';
	//seo
	$webtitle	=	"Xem Phim $tenphim - $tentienganh $chatluong";
	if($info[0][8])
		$webkey		=	$info[0][8].",".$info[0][9];
	else
		$webkey		=	$info[0][9];
	$webdesc	=	"Phim $tenphim $namsanxuat, Xem phim ".get_ascii($tenphim)." online, $tentienganh, $phimtxt";
	autotag($phimid);
	
	//add
	$phimimgz	=	MAIN_URL."/".film_img($phimimg,1);
	$head		=	"<meta property=\"og:url\" content=\"".MAIN_URL.URL_LOAD."\" />
	<meta property=\"og:title\" content=\"$webtitle\">
	<meta property=\"og:description\" content=\"$webdesc\" />
	<meta property=\"og:image\" content=\"$phimimgz\" />
	";
	// playing popup
	$pcz		= 	explode("?hide=",URL_LOAD);
	$showMovie	=	false;
	if($pcz[1]) {
		$showMovie	=	true;
	}
}
elseif($value[0] == "thanh-vien") {
	$ipid		= 	explode("_",URL_LOAD);
	$ipid		=	$ipid[1];
	if ($ipid) {
		$ipid		=	$ipid;
		$ipid = decode_id($ipid);
	}
	else {
		$ipid		= 	explode(".",URL_LOAD);
		$ipid		=	$ipid[1];
	}
	$user	 	=	$db->database("usergroup,
								  username,
								  password,
								  email,
								  usercode,
								  sex,
								  fullname,
								  regdate,
								  birthday,
								  avatar","user","userid = '$ipid'");
	if(!$user)			header("Location: ".ERROR);
	$usergroup		=	groupName($user[0][0]);
	$username		=	$user[0][1];
	$password		=	$user[0][2];
	$email			=	$user[0][3];
	$usercode		=	$user[0][4];
	$sex			=	sexName($user[0][5]);
	$fullname		=	$user[0][6];
	$regdate		=	date("d-m-Y",$user[0][7]);
	$birthday		=	$user[0][8];
	$avatar			=	$user[0][9];
	
	$exdate			=	explode('-',$birthday);
	$dayx			=	$exdate[0];
	$month			=	$exdate[1];
	$year			=	$exdate[2];
	
	$webtitle	=	"$username - $fullname";
	$webkey		=	"$username,$fullname";
	$webdesc	=	"$username - $fullname";
	
	
	//begin pages
	$userurl		=	url_link($_SESSION["ipos_username"],$_SESSION["ipos_userid"],"thanh-vien");
	$userpag		=	url_link($username,$ipid,"thanh-vien");
	$m		= 	explode("?m=",URL_LOAD);
	$m		=	intval($m[1]);
}
elseif($value[0] == "pages") {
	$ipid		= 	explode("_",URL_LOAD);
	$ipid		=	$ipid[1];
	if ($ipid) {
		$ipid		=	$ipid;
		$ipid = decode_id($ipid);
	}
	else {
		$ipid		= 	explode(".",URL_LOAD);
		$ipid		=	$ipid[1];
	}
	$pages		=	$db->database("p_title,p_contents","pages","p_id = '$ipid'");
	$webtitle	=	$pages[0][0]." - ".NAMEWEB;
	$webkey		=	KEYWEB;
	$webdesc	=	DECWEB;
}
elseif($value[0] == "error") {
	$webtitle	=	"KhÃ´ng tÃ¬m tháº¥y trang - ".NAMEWEB;
	$webkey		=	KEYWEB;
	$webdesc	=	DECWEB;
}
elseif($value[0] == "bang-xep-hang") {
	$webtitle	=	"Báº£ng xáº¿p háº¡ng phim, top phim HOT nháº¥t, phim xem nhiá»�u nháº¥t";
	$webkey		=	"xep hang phim, bang xep hang phimbmt.vn, ".KEYWEB;
	$webdesc	=	DECWEB;
	$ipid		= 	explode("?rank=",URL_LOAD);
	$ipid		=	$ipid[1];
}
elseif(!$ipos) {
	$webtitle	=	NAMEWEB;
	$webkey		=	KEYWEB;
	$webdesc	=	DECWEB;
	$head		=	"<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"".MAIN_URL."/rss\" />\n";
}
$webkey		=	mb_strtolower($webkey, 'UTF-8');
?>